<?php

namespace app\api\controller;

use app\api\model\User as UserModel;
use think\Log;

/**
 * 用户管理
 * Class User
 * @package app\api
 */
class User extends Controller
{
    /**
     * 用户自动登录
     * @return array
     * @throws \app\common\exception\BaseException
     * @throws \think\Exception
     * @throws \think\exception\DbException
     */
    public function login()
    {
        $share_id = $this->request->param("share_id");
        Log::record(" <== share_id " . $share_id);
        $model = new UserModel;
        $user_id = $model->login($this->request->post());
        if ($share_id) {
            Log::record("绑定分享者");
            $user = $model::get($user_id);
            if (!$user->upper_id) {
                Log::record("<== set share_id");
                $user->share_id = $share_id;
                $user->save();
            }
        }
        $token = $model->getToken();
        return $this->renderSuccess(compact('user_id', 'token'));
    }



}
